package com.sjtfreaks.jet.movieapp.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.sjtfreaks.jet.movieapp.R;
import com.sjtfreaks.jet.movieapp.activity.LoginActivity;
import com.sjtfreaks.jet.movieapp.activity.MapActivity;
import com.sjtfreaks.jet.movieapp.activity.PayActivity;
import com.youth.banner.Banner;
import com.youth.banner.loader.ImageLoader;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jet on 2018-10-16.
 */

public class UserFragment extends Fragment implements View.OnClickListener {
    private Button bt1;
    private Button bt2;
    private Button bt_exit;
    Banner banner;

    public static UserFragment newInstance(String name){
        Bundle args = new Bundle();
        args.putString("name", name);
        UserFragment fragment = new UserFragment();
        fragment.setArguments(args);
        return fragment;
    }
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_user,null);
        init(view);
        return view;

    }

    private void init(View view) {
        bt_exit =(Button) view.findViewById(R.id.bt_exit);
        bt_exit.setOnClickListener(this);
        bt1 =(Button) view.findViewById(R.id.bt1);
        bt1.setOnClickListener(this);
        bt2 =(Button) view.findViewById(R.id.bt2);
        bt2.setOnClickListener(this);
        //轮播图
        banner = (Banner) view.findViewById(R.id.banner1);
        //本地图片数据（资源文件）
        List<Integer> list=new ArrayList<>();
        list.add(R.mipmap.m1);
        list.add(R.mipmap.m3);
        list.add(R.mipmap.m5);

        banner.setImages(list)
                .setImageLoader(new UserFragment.GlideImageLoader())
                .start();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.bt_exit:
                startActivity(new Intent(getActivity(), LoginActivity.class));
                getActivity().finish();
                break;
            case R.id.bt1:
                startActivity(new Intent(getActivity(), PayActivity.class));
                break;
            case R.id.bt2:
                startActivity(new Intent(getActivity(), MapActivity.class));
                break;
        }
    }
    //加载本地图片
    public class GlideImageLoader extends ImageLoader {
        @Override
        public void displayImage(Context context, Object path, ImageView imageView) {
            Glide.with(context.getApplicationContext())
                    .load(path)
                    .into(imageView);
        }

    }
}
